home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6881 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 20 Feb 1996 17:11:10 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb20101110@qcd.lanl.gov>
  8. References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu>
  9.     <31298D20.41C6@bazis.nl> <ARTHUR.96Feb20143404@gold.Smallworld.co.uk>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: arthur@Smallworld.co.uk's message of 20 Feb 1996 14:34:03 GMT
  14.  
  15. In article <ARTHUR.96Feb20143404@gold.Smallworld.co.uk>
  16. arthur@Smallworld.co.uk (Arthur Chance) writes: 
  17. <snip>
  18.    In article <31298D20.41C6@bazis.nl> Franz Korntner <fkorntne@bazis.nl> writes:
  19.    > j+k will overflow when the result exceeds MAXINT
  20.    > 
  21.    > Thus:  "if (j+k > MAXINT) overflow();" but the operation is undefined
  22.    > if the result overflows, so the expression needs rewriting to make sure
  23.    > this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
  24.  
  25.    As we must be talking about signed ints, because unsigned can't cause
  26.    undefined behaviour by overflow, if k < 0, then MAXINT-k overflows.
  27.  
  28.    Basically, the C *standard* is useless on things like signed overflow
  29.    (or word size, or what happens with right shift of -ve numbers, or
  30.    <insert your favourite "undefined behaviour" gripe here>). You have
  31.    to look carefully at each *implementation* you use. You can usually
  32.  
  33. Actually you are mixing up the concepts of `undefined behaviour' and
  34. `implementation-defined behaviour'. In the case of the former, even
  35. looking at the implementation documentation need not be sufficient: in
  36. the latter, the documentation has to tell you what happens.
  37.  
  38. Cheers
  39. Tanmoy
  40. --
  41. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  42. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  43. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  44. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  45. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  46. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  47.